#include "myLib.h"

unsigned short *videoBuffer = (unsigned short *)0x6000000;

void setPixel(int row, int col, unsigned short color)
{
	videoBuffer[OFFSET(row, col, SCREENWIDTH)] = color;
}

void drawRect(int row, int col, int height, int width, u16 color)
{
	int r;
	for(r=0; r<height; r++)
	{
		DMA[3].src = &color;
		DMA[3].dst = videoBuffer + OFFSET(row+r, col, 240);
		DMA[3].cnt = width | DMA_ON | DMA_SOURCE_FIXED;
	}
}



/*
void drawRect(int row, int col, int height, int width, u16 color)
{
	int r, c;
	for(r=0; r<height; r++)
	{
		for(c=0; c<width; c++)
		{
			setPixel(row+r, col+c, color);
		}
	}
}
*/
void waitForVblank()
{
	while(SCANLINECOUNTER > 160);
	while(SCANLINECOUNTER < 160);
}

void drawImage3(int x, int y, int width, int height, const u16* image)
{
    int r;
    for (r=0; r<height; r++) {  

            DMA[3].src = &image;
            DMA[3].dst = &videoBuffer[OFFSET(x+width, y, 240)];
            DMA[3].cnt = width | DMA_SOURCE_FIXED| DMA_ON | DMA_DESTINATION_INCREMENT; 
            image = &image + (r * width);

    }

}

